package io.renren.modules.hotel.controller;

import com.alibaba.fastjson.JSON;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.hotel.entity.QuestionEntity;
import io.renren.modules.hotel.service.QuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Api(tags = "常见问题功能")
@RestController
@RequestMapping("hotel/question")
public class QuestionController {

    @Autowired
    private QuestionService questionService;

    /**
     * 分页查询所有问题，带条件查询与不带条件查询
     * @param params
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("分页查询所有问题")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page =questionService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 新增问题
     * @param question
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("新增问题")
    public R save(@RequestBody QuestionEntity question){
        questionService.save(question);
        return R.ok();
    }

    /**
     * 批量删除问题
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    @ApiOperation("根据id删除问题")
    public R delete(@RequestBody Integer[] ids){
        questionService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }
    /*public R delete(@RequestBody String ids){
        List<Integer> idList = JSON.parseArray(JSON.parseObject(ids).getString("ids"), Integer.class);
        questionService.removeByIds(idList);
        return R.ok();
    }*/

    /**
     * 修改问题
     * @param question
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("修改问题")
    public R update(@RequestBody QuestionEntity question){
        questionService.updateById(question);
        return R.ok();
    }
}
